package edu.cicese.alz.reports;

import edu.cicese.alz.swing.JColorButton;
import edu.cicese.alz.swing.JNonEmptyTextField;
import edu.cicese.alz.swing.SwingUtil;

import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import java.awt.Color;
import java.util.HashMap;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 23/07/12
 * Time: 08:44 PM
 */
public class NFCTag {
	private JLabel label;
	private JCheckBox tagCheckBox, profileCheckBox;
	private JNonEmptyTextField textField;
	private JColorButton tagButton;
	private HashMap<NFCProfile, JColorButton> profileButtons = new HashMap<>();

	private boolean profiled;

	private String tagName;
	private Color color;

	public NFCTag(JLabel label, JCheckBox tagCheckBox, JNonEmptyTextField textField, JColorButton tagButton) {
		this.label = label;
		this.tagCheckBox = tagCheckBox;
		this.textField = textField;
		textField.setCaretPosition(0);
		this.tagButton = tagButton;
		this.profileCheckBox = SwingUtil.createCheckBox(getText(), 100, 20);
	}

	public NFCTag(JCheckBox profileCheckBox, JColorButton tagButton) {
		this.profileCheckBox = profileCheckBox;
		this.tagButton = tagButton;
	}

	public NFCTag(String tagName, Color color) {
		this.tagName = tagName;
		this.color = color;
	}

	public String getText() {
		return textField.getText();
	}

	public void setText(String text) {
		textField.setText(text);
	}

	public boolean isSelected() {
		return tagCheckBox.isSelected();
	}

	public void setSelected(boolean selected) {
		tagCheckBox.setSelected(selected);
	}

	public boolean isProfiled() {
		return profiled;
	}

	public void setProfiled(boolean profiled, Icon icon) {
		this.profiled = profiled;
		label.setIcon(icon);
	}

	public JColorButton getTagButton() {
		return tagButton;
	}

	public Color getColor() {
		return tagButton.getBackground();
	}

	public JColorButton getProfileButton(NFCProfile profile) {
		return profileButtons.get(profile);
	}

	public Color getProfileColor(NFCProfile profile) {
		return getProfileButton(profile).getBackground();
	}

	public void addToProfile(NFCProfile profile) {
		profileButtons.put(profile, SwingUtil.createColorButton(20, 20, tagButton.getBackground()));
	}

	public void addToProfile(NFCProfile profile, Color color) {
		profileButtons.put(profile, SwingUtil.createColorButton(20, 20, color));
	}

	public void removeFromProfile(NFCProfile profile) {
		profileButtons.remove(profile);
	}

	public JLabel getLabel() {
		return label;
	}

	public JCheckBox getTagCheckBox() {
		return tagCheckBox;
	}

	public JCheckBox getProfileCheckBox() {
		return profileCheckBox;
	}

	public JNonEmptyTextField getTextField() {
		return textField;
	}
}
